using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter23
{
	/// <summary>
	/// Example06: Electric Field of a Dipole
	/// An electric dipole is defined as a positive charge q
	/// and a negative charge -q separated by a distance 2a.
	/// For the dipole shown in Figure, find the electric field
	/// E at P due to the dipole, where P is a distance y >> a
	/// from the orgin.
	/// E = k_e 2q a /(y^2 + a^2)^{3/2}	
	/// </summary>
	public class Example06
	{
		public Example06()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			double q = 5.0E-6;
			double a = 0.0001;
			double y = 2.0;
			L.ElectricCharge q1 = new L.ElectricCharge();
			q1.C = -q;
			L.ElectricCharge q2 = new L.ElectricCharge();
			q2.C = q;
				
			L.Position r1 = new L.Position();
			r1.X = a;
			L.Position r2 = new L.Position();
			r2.X = -a;
			L.Position r3 = new L.Position();
			r3.Y = y;

			L.ElectricField E1 = new L.ElectricField(q1,r1,r3);
			L.ElectricField E2 = new L.ElectricField(q2,r2,r3);
			L.Vector f = E1 + E2;

			result+=Convert.ToString(f.X)+" i + ";
			result+=Convert.ToString(f.Y)+" j + ";
			result+=Convert.ToString(f.Z)+" k \r\n";
			result+=Convert.ToString(L.Constant.CoulombConstant
				*2.0*q*a/Math.Pow(y*y+a*a,3.0/2.0));
		}
	}
}
